﻿using SaaS.Model.Enums;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using XCore.Domain.Entities;

namespace SaaS.Model.Entity.Gateways
{
    /// <summary>
    /// 公告（站内信）
    /// </summary>
    [Table("Gate_Notices")]
    public class Notice : Entity<int>, IHasCreateionIpAddress, IHasCreationTime
    {
        public int? TenantId { get; set; }
        /// <summary>
        /// 标题
        /// </summary>
        [Required]
        [StringLength(128)]
        public string Title { get; set; }
        /// <summary>
        /// 状态
        /// </summary>
        public ArticleStatus Status { get; set; }
        /// <summary>
        /// 类型
        /// </summary>
        public NoticeType Type { get; set; }
        /// <summary>
        /// 发布时间，可定时发布
        /// </summary>
        public DateTime? ReleaseTime { get; set; }
        /// <summary>
        /// 浏览量
        /// </summary>
        public long Flow { get; set; }
        /// <summary>
        /// 配置字段信息
        /// </summary>
        public string SettingString { get; set; }
        /// <summary>
        /// 重要性
        /// </summary>
        public byte Importance { get; set; }
        /// <summary>
        /// 摘要
        /// </summary>
        [StringLength(512)]
        public string Summary { get; set; }
        /// <summary>
        /// 内容
        /// </summary>
        public string Content { get; set; }

        /// <summary>
        /// 配置类
        /// </summary>
        private NoticeSetting _noticeSetting;
        [NotMapped]
        public NoticeSetting NoticeSetting
        {
            get
            {
                if (_noticeSetting == null)
                {
                    _noticeSetting = new NoticeSetting(this.SettingString);
                }
                return _noticeSetting;
            }
            set
            {
                _noticeSetting = value;
            }
        }


        public int? CreatorUserId { get; set; }
        public DateTime CreationTime { get; set; }
        public int? LastModifyUserId { get; set; }
        public DateTime? LastModifyDate { get; set; }
        public int? DeleteUserId { get; set; }
        public bool IsDeleted { get; set; }
        public DateTime? DeleteTime { get; set; }
        public string IP { get; set; }
    }
}
